package com.atguigu.bigdata.chapter05.transform;

import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @Author lzc
 * @Date 2022/9/2 10:26
 */
public class Flink08_Union {
    public static void main(String[] args) {
        Configuration conf = new Configuration();
        conf.setInteger("rest.port", 2000);
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
        env.setParallelism(2);
        
        
        DataStreamSource<Integer> s1 = env.fromElements(1, 10, 3, 6, 9, 11);
        DataStreamSource<Integer> s2 = env.fromElements(100, 200, 300);
        
        s1
            .union(s2)
            .map(new MapFunction<Integer, String>() {
                @Override
                public String map(Integer value) throws Exception {
                    return value + "<>";
                }
            })
            .print();
        
        
        try {
            env.execute();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
/*
connect:
1. connect一次只能连接两个流
2. 两个流的类型可以不一样
    实际使用的时候,大部分都是不一样
    
union
1. union可以一次连接多个流
2. 多个流的数据类型必须一致



 */